<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('系统管理员操作界面')"/>
    <!--<th:block th:include="include :: select2-css" />-->
    <th:block th:include="include :: bootstrap-select-css"/>
    <link th:href="@{/ruoyi/css/font-awesome.css}" rel="stylesheet"/>
    <link th:href="@{/ruoyi/css/jquery-confirm.min.css}" rel="stylesheet"/>
</head>
<style type="text/css">
    * {
        margin: 0;
        padding: 0;
        font-family: "微软雅黑";
        font-size: 12px;
    }

    .box {
        width: 390px;
        height: 400px;
        border: solid 1px #ddd;
        background: #FFF;
        position: absolute;
        left: 50%;
        top: 42%;
        margin-left: -195px;
        margin-top: -160px;
    }

    .box h2 {
        font-weight: normal;
        color: #666;
        font-size: 16px;
        line-height: 46px;
        height: 46px;
        overflow: hidden;
        text-align: center;
        border-bottom: solid 1px #ddd;
        background: #f7f7f7;
    }

    .input_box {
        width: 350px;
        padding-bottom: 15px;
        margin: 0 auto;
        overflow: hidden;
    }

    .input_box input {
        float: left;
        width: 348px;
        height: 40px;
        font-size: 14px;
        border: solid 1px #ddd;
        text-indent: 10px;
        outline: none;
        line-height: 40px;
    }

    .in input {
        float: left;
        width: 200px;
        height: 40px;
        font-size: 14px;
        border: solid 1px #ddd;
        text-indent: 10px;
        outline: none;
        line-height: 40px;
        margin-left: 20px;
    }

    .inc input {
        float: left;
        width: 40px;
        height: 40px;
        font-size: 14px;
        border: solid 1px #ddd;
        text-indent: 10px;
        outline: none;
        line-height: 40px;
        margin: 0px 0px 0px 10px;
    }

    .input_box button {
        width: 350px;
        height: 48px;
        background: #3f89ec;
        border: none;
        border-radius: 2px;
        outline: none;
        cursor: pointer;
        font-size: 16px;
        color: #FFF;
        margin-top: 15px;
    }

    .glylogin {
        display: block;
        width: 100px;
        height: 48px;
        background: #3f89ec;
        border: none;
        border-radius: 2px;
        font-size: 16px;
        color: #FFF;
        text-align: center;
        float: right
    }

    #error_box {
        height: 40px;
        width: 350px;
        margin: 0 auto;
        line-height: 40px;
        color: #fc4343;
    }
    @media screen and (min-width: 768px) {
        #glylab{
            margin: 5px 0px 0px 5px;font-size: 18px
        }
    }
    @media screen and (max-width: 768px) {
        #glylab{
            margin: 5px 0px 0px 5px;font-size: 16px
        }
    }
</style>
<body class="gray-bg" onkeydown="keyLogin()">


<!-- 添加部门与员工模态框开始 -->
<div class="modal fade" id="bmModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
     data-backdrop="static" data-keyboard="false">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">管理员登录</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">登录名称</label>
                        <div class="col-sm-9">
                            <input type="text" name="loginName" class="form-control" id="loginname" placeholder="请输入登录名称" >
                            <span class="help-block"></span>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label">公司名称</label>
                        <div class="col-sm-7">
                            <select name="bm" class="form-control m-b" id="bm_bm">
                            </select>
                            <span class="help-block"></span>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label">登录密码</label>
                        <div class="col-sm-9">
                            <input type="text" name="loginPassword" class="form-control" id="loginpassword"
                                   placeholder="请输入登录密码">
                            <span class="help-block"></span>
                        </div>
                    </div>

                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" id="tj_bm_btn" onclick="glydl()">登录</button>
            </div>
        </div>
    </div>
</div>
<!--添加部门与员工模态框结束-->

<!--<div>-->
    <!--<button type="button" class="glylogin">管理员登录</button>-->
<!--</div>-->
<div class="box">
    <h2>登录</h2>
    <div id="error_box"></div>
    <form>
        <div class="input_box">
            <select class="form-control" name="gsid" id="gsid">
            </select>
        </div>
        <div class="input_box">
            <input type="text" placeholder="请输入账户名" name="loginName" id="uname" value="mengdz"/>
        </div>
        <div class="in">
            <input type="password" placeholder="请输入密码" name="loginPassword" id="upass" value="admin"/>
        </div>
        <div class="inc">
            <input type="checkbox" name="isselect" id="sign" value="管理登录"/><label for="sign" id="glylab">管理登录</label>
        </div>
        <div class="input_box">
            <button type="button" id="login">登录</button>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: bootstrap-select-js"/>
<script th:src="@{/ruoyi/js/jquery-confirm.min.js}"></script>
<script th:src="@{/ruoyi/js/jquery.form.js}"></script>
<script th:inline="javascript">
    var autologin = [[${session.autologin}]]
    function keyLogin() {
        if (event.keyCode==13){
            document.getElementById('login').click();
        }
    }
    // function glydl() {
    //     var gsid = $("#bm_bm").val()
    //     var loginName = $("#loginname").val()
    //     var loginPassword = $("#loginpassword").val()
    //     $.ajax({
    //         url: "/sbgl/sbuser/login/" + gsid + "/" + loginName + "/" + loginPassword,
    //         type: 'get',
    //         success: function (result) {
    //             if (result != "") {
    //                 window.location.href = "/index"
    //             }
    //         }
    //     })
    // }
    $(".glylogin").click(function () {
        $("#bmModal").modal({
            backdrop: "static"
        });
        $("#loginname").val("")
        $("#loginpassword").val("")
        gsmc('#bm_bm')
    })

    function gsmc(ele) {
        $.ajax({
            url: '/sbgl/gsxxb/getgsxxb',
            type: 'get',
            success: function (result) {
                $(ele).empty();
                var options = "";   //字符串拼接
                $(ele).append('<option value="admin">请选择公司名称</option>');
                for (var i in result) {  //遍历json数组
                    options += "<option value='" + result[i].gsid + "'>" + result[i].gs + "</option>"
                }
                $(ele).append(options);
            }
        })
    }
    $(document).ready(function () {
        gsmc('#gsid')
        if (autologin==0){
            $("#uname").val("")
            $("#upass").val("")
        }
        console.log($.ajax({async:false}).getResponseHeader("Date"))
    })
    $("#login").click(function () {
        var gsid = $("#gsid").val()
        var loginName_gly = window.btoa($("#uname").val())
        var loginPassword_gly = window.btoa($("#upass").val())
        var loginName = $("#uname").val()
        var loginPassword = $("#upass").val()
        // if (loginName_gly=="YWRtaW5pc3RyYXRvcg==") {
        //     if (loginPassword_gly=="YWRtaW5pc3RyYXRvcjM2ODMyOTc=") {
        //         window.location.href = "/index_gly"
        //         return false;
        //     }else {
        //         $.alert("你登录的超级管理员的账号不正确")
        //         return false;
        //     }
        // }
        if (loginName == "administrator") {
            $("#gsid").val("admin")
            if ($('#sign').prop('checked')) {
                var flag = dlajax($("#gsid").val(), loginName, loginPassword)
                if (flag != "") {
                    if ($('#sign').prop('checked')) {
                        window.location.href = "/index"
                    }
                }
            } else {
                $.alert("请勾选管理登录","温馨提示")
                return false
            }
        } else {
            var flag = dlajax($("#gsid").val(), loginName, loginPassword)[0].isgly
            if (flag== "是") {
                if ($('#sign').prop('checked')) {
                    window.location.href = "/index"
                } else {
                    window.location.href = "/sbgl/sbxxb/sbxxb"
                }
            }else {
                if ($('#sign').prop('checked')) {
                    $.alert("当前你登录的用户不是管理员不用勾选管理登录","温馨提示")
                } else {
                    window.location.href = "/sbgl/sbxxb/sbxxb"
                }
            }
        }
    })

    function dlajax(gsid,loginName,loginPassword) {
        var date=""
        $.ajax({
            url: "/sbgl/ygxxb/login/" + gsid + "/" + loginName + "/" + loginPassword,
            type: 'get',
            async: false,
            success: function (result) {
                if (result!=""){
                  date=result
                }
            },
            error:function(XMLHttpRequest, textStatus){
                // 状态码
                console.log(XMLHttpRequest.status);
                // 状态
                console.log(XMLHttpRequest.readyState);
                // 错误信息
                console.log(textStatus);
                if(XMLHttpRequest.readyState==0){
                    // 对应登录超时问题，直接跳到登录页面
                    location.href='/login';
                }else{
                    // $.messages.alert('提示','系统内部错误，请联系管理员处理！','info');
                    // $.alert("你公司名称与对应的用户名和密码不匹配")
                }
            },
        })
        return date;
    }

</script>
</body>
</html>